package com.baitengsoft.patentapimonitor.api.controller;

import com.baitengsoft.patentapimonitor.api.entity.WebUserinfoEntity;
import com.baitengsoft.patentapimonitor.api.model.WebMonAnalysisInfo;
import com.baitengsoft.patentapimonitor.api.model.WebMonInvalidAnalysisInfo;
import com.baitengsoft.patentapimonitor.api.service.PacPatentinfoOutService;
import com.baitengsoft.patentapimonitor.api.service.PacPatentinfoService;
import com.baitengsoft.patentapimonitor.common.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 监控分析
 * @author Chen 2018/1/15
 */
@RestController
@RequestMapping("api/v1/web/monanalysis")
@Api(value = "前台-专利监控-监控分析",description = "监控分析")
public class WebMonAnalysisController extends AbstractController {
    @Autowired
    private PacPatentinfoService pacPatentinfoService;
    @Autowired
    private PacPatentinfoOutService pacPatentinfoOutService;

    /**
     * 专利权转入WebAreaStatisticInfo
     */
    @ApiOperation(value ="转入")
    @GetMapping("/in")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "sort", value = "排序字段", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "order", value = "排序方式[desc asc]", required = false)
    })
    public Res getInList(String sort, String order){
        System.out.print(new Date());
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<WebMonAnalysisInfo> infos = pacPatentinfoService.getInList(userInfo.getPlatformid(), order, sort);
        System.out.print(new Date());
        return Res.ok().put("list",infos);
    }

    /**
     * 专利权转出
     */
    @ApiOperation(value ="转出")
    @GetMapping("/out")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "sort", value = "排序字段", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "order", value = "排序方式[desc asc]", required = false)
    })
    public Res getOutList(String sort, String order){
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<WebMonAnalysisInfo> infos = pacPatentinfoService.geOutList(userInfo.getPlatformid(), order, sort);
        return Res.ok().put("list",infos);
    }

    /**
     * 专利权失效
     */
    @ApiOperation(value ="失效")
    @GetMapping("/invalid")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "sort", value = "排序字段", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "order", value = "排序方式[desc asc]", required = false)
    })
    public Res getInvalidList(String sort, String order){
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<WebMonInvalidAnalysisInfo> infos = pacPatentinfoService.geInvalidList(userInfo.getPlatformid(), order, sort);
        return Res.ok().put("list",infos);
    }
}
